package com.yuncheng.oaApi.FlowController;


import com.yuncheng.oaApi.vo.OaFlowVo;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.Result;
import com.yuncheng.oaApi.vo.SpcytssxVo;
import com.yuncheng.spcyApi.service.ISpcyLogService;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.oaApi.FlowService.NewBxTssxsqFlowService;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.oaApi.busService.MyLcFlowService;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.oaApi.mapper.SpcyJcyFybxdtssxsqFlowMapper;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.*;
import groovy.lang.Lazy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import utils.LogUtils;
import utils.ObjectToMapUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

@Api(tags = "NEW_BX-特殊事项申请")
@RestController
@RequestMapping("/api/spzx-oa/bx-tssqsq")
public class NewBxTssqsqFlowController {
    private static final Logger log = LoggerFactory.getLogger(NewBxTssqsqFlowController.class);

    @Resource
    private IOaSpcySqsxJobService spcySqsxJobService;

    @Resource
    @Lazy
    private IOaSysTzMessageService sysTzMessageService;

    @Resource
    @Lazy
    private MyLcFlowService myLcFlowService;

    @Resource
    @Lazy
    private ISpcyLogService spcyLogService;

    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;


    @Resource
    @Lazy
    private NewBxTssxsqFlowService newBxTssxsqFlowService;

    @Resource
    @Lazy
    private IOaSpcyJcyFybxdtssxsqService spcyFybxdtssxsqService;

    @Resource
    @Lazy
    private SpcyJcyFybxdtssxsqFlowMapper spcyJcyFybxdtssxsqService;

    @Resource
    @Lazy
    private IOaSpcyJcyFybxdService spcyJcyFybxdService;






    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程监控-分页查询")
    @ApiOperation(value = "流程监控-分页查询")
    @GetMapping("flowJkPage")
    public HttpResult flowJkPage(
            SpcytssxVo spcytssxVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        spcytssxVo.setFlcmc(OaFlowConstant.BXD_TSSXSQ_NAME);
        Page<SpcytssxVo> page = new Page<>(pageNo, pageSize);

        IPage<SpcytssxVo> list = null;
        if (StringUtils.isNotBlank(spcytssxVo.getOaid())){
            OaSpcyJcyFybxdtssxsq xzswsp = spcyFybxdtssxsqService.getById(spcytssxVo.getOaid());
            if (xzswsp != null){
                list = spcyJcyFybxdtssxsqService.flowJkPage(page,onlyCurrentUser,user,spcytssxVo);
            }
        }

        return HttpResult.ok(list);
    }

    /**
     * 流程列表分页查询
     * @param
     * @param pageNo
     * @param pageSize
     * @param onlyCurrentUser
     * @return
     */
    @AutoLog(value = "流程列表-分页查询")
    @ApiOperation(value = "流程列表-分页查询")
    @GetMapping("flowJobPage")
    public HttpResult<?> flowJobPage(
            SpcytssxVo spcytssxVo,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        spcytssxVo.setFlcmc(OaFlowConstant.BXD_TSSXSQ_NAME);
        if (StringUtils.isBlank(spcytssxVo.getFblzt())) {
            spcytssxVo.setFblzt(OaCommonFlowConstant.BLZT_DB);
        }
        Page<SpcytssxVo> page = new Page<>(pageNo, pageSize);
        IPage<SpcytssxVo> list = spcyJcyFybxdtssxsqService.flowJobPage(page, onlyCurrentUser, user, spcytssxVo);
        return HttpResult.ok(list);
    }


    /**
     * 我的已办
     */
    @AutoLog(value = "流程列表-我的已办")
    @ApiOperation(value = "流程列表-我的已办")
    @GetMapping("myJobPage")
    public HttpResult<?> myJobPage(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            SpcytssxVo spcytssxVo) {
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        Page<SpcytssxVo> page = new Page<>(pageNo, pageSize);
        IPage<SpcytssxVo> list = spcyJcyFybxdtssxsqService.myYbFlowPage(page, true, user, spcytssxVo);
        return HttpResult.ok(list);
    }


    /**
     * 数据修订
     */
    @AutoLog(value = "列表-数据修订")
    @ApiOperation(value = "列表-数据修订")
    @GetMapping("Pagesjxd")
    public HttpResult<?> Pagesjxd(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            SpcytssxVo spcytssxVo) {

        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }

        Page<SpcytssxVo> page = new Page<>(pageNo, pageSize);
        IPage<SpcytssxVo> list = spcyJcyFybxdtssxsqService.myYbFlowPage(page, false, user, spcytssxVo);
        return HttpResult.ok(list);
    }






    @AutoLog(value = "发起特殊事项申请")
    @ApiOperation(value = "发起特殊事项申请")
    @PostMapping(value = "initBzFlow")
    public HttpResult<?> initBzFlow(@RequestBody OaSpcyJcyFybxdtssxsq spcyJcybxdtssxsq) throws Exception {

        String oaid = "";
        //当前人的id
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser == null) {
            return HttpResult.error("当前登录已失效，请重新登录");
        }
        if (StringUtils.isNotBlank(spcyJcybxdtssxsq.getId())){
            OaSpcyJcyFybxdtssxsq nkids = spcyFybxdtssxsqService.getById(spcyJcybxdtssxsq.getId());

            ConvertUtils.register(new DateConvert(), Date.class);
            try {
                BeanUtils.populate(nkids, BeanUtils.describe(spcyJcybxdtssxsq));
            } catch (IllegalAccessException e) {
                log.error("出错-保存事项【非法访问异常】,{}", e.getMessage());
            } catch (InvocationTargetException e) {
                log.error("出错-保存事项【调用TargetException】,{}", e.getMessage());
            } catch (NoSuchMethodException e) {
                log.error("出错-找不到可用方法", e.getMessage());
            }
            oaid = spcyJcybxdtssxsq.getId();

            // Date日期单独做处理

            spcyJcybxdtssxsq.setFsqzt("已申请");
            spcyJcybxdtssxsq.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
            spcyFybxdtssxsqService.updateById(nkids);
        }else {
            oaid = GetUuIdUtils.ReplaceUuId();

            spcyJcybxdtssxsq.setId(oaid);
            spcyJcybxdtssxsq.setFsqzt("已申请");
            spcyJcybxdtssxsq.setFlczt(OaCommonFlowConstant.FLOW_LCZB);

            OaSpcyJcyFybxd oaSpcyJcyFybxd = spcyJcyFybxdService.getById(spcyJcybxdtssxsq.getFbxdid());

            if (StringUtils.isNotBlank(spcyJcybxdtssxsq.getFewfybxsqrxm())){
                spcyJcybxdtssxsq.setFsqr(spcyJcybxdtssxsq.getFewfybxsqrxm());
                spcyJcybxdtssxsq.setFsqrid(spcyJcybxdtssxsq.getFewfybxsqrid());
            }
            if(StringUtils.isNotBlank(spcyJcybxdtssxsq.getFwxfsqrxm())){
                spcyJcybxdtssxsq.setFsqr(spcyJcybxdtssxsq.getFwxfsqrxm());
                spcyJcybxdtssxsq.setFsqrid(spcyJcybxdtssxsq.getFwxfsqrid());
            }



//            spcyJcybxdtssxsq.setFsqr(spcyJcyFybxd.getFjbr());
//            spcyJcybxdtssxsq.setFsqrid(spcyJcyFybxd.getFjbrid());

            spcyFybxdtssxsqService.save(spcyJcybxdtssxsq);
        }

        /**
         * @Author: lhb
         * @Description : 是否发起流程   如果是开始申请就跳转流程
         *               在这里设置  指定下个环节节点 做当前跳转流程的判断，然后设置变量接收环节的值，写到nextNodeName中
         * @DateTime:
         * @Params: Fsffqlc
         */
        String msg = "保存成功";
        String lcmbCode = OaFlowConstant.BXD_TSSXSQ;

        OaJobEntity job = new OaJobEntity();
        // 初始化流程
        Result result = newBxTssxsqFlowService.createProcess(lcmbCode,oaid, currentUser);
        //做一次规则校验 如果查到此oaid 在表中已经插入 那就执行更新
        OaSpcyJcyFybxdtssxsq spcyJcybxdtssxsq1 = spcyFybxdtssxsqService.getById(oaid);
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        String bt = new String();
        String zy = new String();
        if (StringUtils.isNotBlank(spcyJcybxdtssxsq.getFlcbm()) && spcyJcybxdtssxsq.getFlcbm().equals(OaFlowConstant.NK_CCSP)){
             bt = currentUser.getName()+"提交的特殊事项申请"; //标题
             zy = "申请日期:["+ spcyJcybxdtssxsq1.getFsqrq() +"]"+"\n"
                    +"项目内容:["+ newBxTssxsqFlowService.getms(oaid,spcyJcybxdtssxsq1.getFsxsqid(),OaFlowConstant.NK_CCSP) + "]"+"\n"
                    +"申请类型"+"["+ spcyJcybxdtssxsq1.getFsqlx() +"]"+"\n";
        }else {
            if (StringUtils.isNotBlank(spcyJcybxdtssxsq.getFewfybxsqrxm())){
                bt = spcyJcybxdtssxsq.getFewfybxsqrxm()+"提交的特殊事项申请"; //标题
                zy = "申请日期:["+ spcyJcybxdtssxsq1.getFsqrq() +"]"+"\n"
                        +"项目内容:["+ newBxTssxsqFlowService.getms(oaid,spcyJcybxdtssxsq1.getFsxsqid(),OaFlowConstant.NK_CCSP) + "]"+"\n"
                        +"申请类型"+"["+ spcyJcybxdtssxsq1.getFsqlx() +"]"+"\n";
            }
            if(StringUtils.isNotBlank(spcyJcybxdtssxsq.getFwxfsqrxm())){
                bt = spcyJcybxdtssxsq.getFwxfsqrxm()+"提交的特殊事项申请"; //标题
                zy = "申请日期:["+ spcyJcybxdtssxsq1.getFsqrq() +"]"+"\n"
                        +"项目内容:["+ newBxTssxsqFlowService.getms(oaid,spcyJcybxdtssxsq1.getFsxsqid(),OaFlowConstant.NK_CCSP) + "]"+"\n"
                        +"申请类型"+"["+ spcyJcybxdtssxsq1.getFsqlx() +"]"+"\n";
            }


        }

        if (oaProcessBusinessList.size() == 0){
            //初始化的时候 像 流程业务主表添加拼接初始化数据
            oaProcessBusinessService.addProcess(oaid,zy,bt,lcmbCode,OaFlowConstant.OA);

        }else {
            String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
            OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
            oaProcessBusiness.setFzy(zy);
            oaProcessBusinessService.updateById(oaProcessBusiness);

        }

        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }else {
            job = (OaJobEntity)result.getResult();
            if (job != null) {
                // 是否提交流程
                if(StringUtils.isBlank(oaid)){
                    return HttpResult.error("参数丢失");
                }
                String nextNodeId = "";
                String nextNodeDbrId = "";
                if (StringUtils.isNotBlank(spcyJcybxdtssxsq.getFsffqlc()) && spcyJcybxdtssxsq.getFsffqlc().equals(OaCommonFlowConstant.SFFQLC_YES)) {


                    spcyJcybxdtssxsq.setFsqzt("已申请");
                    if (StringUtils.isBlank(spcyJcybxdtssxsq.getFlczt())) {
                        spcyJcybxdtssxsq.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
                    }
                    Result result1 = newBxTssxsqFlowService.passJob(oaid,job.getId(),"同意", nextNodeId, nextNodeDbrId);
                    if (!result1.isSuccess()) {
                        return HttpResult.error(result.getMessage());
                    }
                    msg = "提交成功";
                    //提交完成后 更新通知信息
                    sysTzMessageService.tjMessage(oaid);

                    List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                            .eq(OaProcessBusiness::getFpid, oaid));
                    OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
                    OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
                    byId1.setFsfkch(0);
                    String upatezy = "申请日期:["+ spcyJcybxdtssxsq.getFsqrq() +"]"+"\n"
                            +"项目内容:["+ newBxTssxsqFlowService.getms(oaid,spcyJcybxdtssxsq.getFsxsqid(),OaFlowConstant.NK_CCSP) + "]"+"\n"
                            +"申请类型"+"["+ spcyJcybxdtssxsq.getFsqlx() +"]"+"\n";
                    byId1.setFzy(upatezy);

                    byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
                    oaProcessBusinessService.updateById(byId1);
                    myLcFlowService.recall(oaid);
                }
            }
        }

        HashMap map = new HashMap();
        map.put("msg",msg);
        map.put("nkMap",spcyJcybxdtssxsq);
        map.put("jobMap",job);

        return HttpResult.ok(map);
    }

    /**
     * 内控-特殊事项申请
     */
    @AutoLog(value = "内控-特殊事项申请保存")
    @ApiOperation(value = "内控-特殊事项申请保存")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody OaFlowVo oaFlowVo) {
        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SAVE; // 保存

        String jobId = oaFlowVo.getJobid(); // 当前流程任务id
        String oaid = oaFlowVo.getOaid(); // 当前办公主键id
        String opinion = oaFlowVo.getOpinion(); // 办理意见

        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.NK_CCSP);
        }
        if (StringUtils.isBlank(jobId)){
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        // 流程处理
        Result httpResult = newBxTssxsqFlowService.handleFlow(oaFlowVo, null, jobId, oaid, submitType, opinion);
        if (!httpResult.isSuccess()){
            return HttpResult.error(httpResult.getMessage());
        }
        Map map = new HashMap();
        HttpResult<Object> res = new HttpResult<>(true);
        res.setMessage("保存成功");
        res.setResult(map);
        return res;
    }


    @AutoLog(value = "内控-特殊事项申请提交")
    @ApiOperation(value = "内控-特殊事项申请提交")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody OaFlowVo oaFlowVo) {

        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        String jobId = oaFlowVo.getJobid();
        String oaid = oaFlowVo.getOaid();
        String opinion = oaFlowVo.getOpinion();
        OaSpcyJcyFybxdtssxsq oaId = spcyFybxdtssxsqService.getById(oaid);
        OaJobEntity jobid = spcySqsxJobService.getById(jobId);
        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.TSSXSQ_SQ);
        }

        if (jobid.getFhjmc().equals(OaFlowConstant.TSSXSQ_SQ)){
            //重新获取摘要信息
            OaSpcyJcyFybxdtssxsq nkRsCcsp1 = spcyFybxdtssxsqService.getById(oaid);
            List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                    .eq(OaProcessBusiness::getFpid, oaid));
            String bt = currentUser.getName()+"提交的特殊事项申请"; //标题
            String zy = "申请日期:["+ nkRsCcsp1.getFsqrq() +"]"+"\n";
            if (oaProcessBusinessList.size() == 0){
                //初始化的时候 像 流程业务主表添加拼接初始化数据
                oaProcessBusinessService.addProcess(oaid,zy,bt,OaFlowConstant.BXD_TSSXSQ,OaFlowConstant.OA);

            }else {
                String id = oaProcessBusinessList.get(0).getId();  //当前已经插入的主键id 然后更新 摘要信息
                OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
                oaProcessBusiness.setFzy(zy);
                oaProcessBusinessService.updateById(oaProcessBusiness);

            }

        }else if (jobid.getFhjmc().equals(OaFlowConstant.TSSXSQ_ZXZR)) {

        } else {
            oaId.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        }
        if (StringUtils.isBlank(oaId.getFsffqlc())) {
            oaId.setFsffqlc(OaCommonFlowConstant.SFFQLC_YES);
        }

        spcyFybxdtssxsqService.updateById(oaId);

        if (StringUtils.isBlank(jobId)) {
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        /* if (StringUtils.isBlank(opinion)){
            return HttpResult.error("请填写办理意见");2
        }*/

        OaJobEntity nowJob = null;
        Result httpResult1 = newBxTssxsqFlowService.handleFlow(oaFlowVo, nowJob, jobId, oaid, submitType, opinion);
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }
        List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
        OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
        byId1.setFsfkch(0);


        byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
        oaProcessBusinessService.updateById(byId1);

        //提交完成后 更新待办信息
        sysTzMessageService.tjMessage(oaid);
        myLcFlowService.recall(oaid);


        return HttpResult.ok("提交成功");
    }





    /**
     * 批量查询
     */
    @AutoLog(value = "批量查询")
    @ApiOperation(value = "批量查询")
    @ApiImplicitParam(value = "jobids", name = "jobids", required = true)
    @GetMapping(value = "queryBatchJobByJobIds")
    public HttpResult<?> queryBatchJobByJobIds(@RequestParam("jobids")String jobids) {
        if (StringUtils.isBlank(jobids)) {
            return HttpResult.error("参数不能为空,请选择数据");
        }
        List<Map> mapList = new ArrayList<>();
        List<String> jobidsList = Arrays.asList(jobids.split(","));
        if (CollectionUtils.isNotEmpty(jobidsList)) {
            for (String jobid : jobidsList){
                mapList.add(newBxTssxsqFlowService.getJobConcernByJobId(jobid));
            }
        }
        return HttpResult.ok(mapList);
    }

    /**
     * 查询当前流程任务详情-通过当前流程任务id
     */
    @AutoLog(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiOperation(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiImplicitParam(value = "jobid", name = "流程任务id", required = true)
    @GetMapping(value = "queryJobByJobId")
    public HttpResult<?> queryJobByJobId(@RequestParam("jobid") String jobid) {
        if (StringUtils.isBlank(jobid)) {
            return HttpResult.error("流程任务id不能为空");
        }
        Map map = newBxTssxsqFlowService.getJobConcernByJobId(jobid);
        return HttpResult.ok(map);
    }

    /**
     * 获取已办列表-通过当前流程id-自定义退回
     *
     * @param jobid
     * @return
     */
    @AutoLog(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiOperation(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid", value = "流程任务id"),
            @ApiImplicitParam(name = "isZdhj", value = "是否指定环节，默认：true，指定")
    })
    @GetMapping(value = "queryAllYbJob")
    public HttpResult<?> queryAllYbJob(@RequestParam(value = "jobid", defaultValue = "") String jobid,
                                       @RequestParam(value = "isZdhj", defaultValue = "true") boolean isZdhj) {
        List<Map<String, String>> currentJobPrevious = newBxTssxsqFlowService.getCurrentJobPrevious(jobid, isZdhj);
        return HttpResult.ok(currentJobPrevious);
    }

    /**
     * 退回环节
     *
     * @return
     */
    @AutoLog(value = "自定义-退回环节")
    @ApiOperation(value = "自定义-退回环节")
    @PostMapping(value = "returnUpperzdyFlowJob")
    public HttpResult<?> returnUpperzdyFlowJob(@RequestBody OaReturnVo oaReturnVo) {
        newBxTssxsqFlowService.returnZdJob(oaReturnVo);

        //退回更新通知信息
        OaJobEntity oaJobEntity = spcySqsxJobService.getById(oaReturnVo.getJobid());
        String fpid = oaJobEntity.getFpid();
        sysTzMessageService.endMessage(fpid,false,false,true);

        return HttpResult.ok("退回成功");
    }

    @AutoLog(value = "删除出差申请")
    @ApiOperation(value = "删除出差申请")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobids",value = "流程任务id,逗号分割",required = true)
    })
    @DeleteMapping(value = "deleteLgqsFlowJob")
    public HttpResult<?> deleteLgqsFlowJob(@RequestParam(value = "jobids") String jobids){
        if (StringUtils.isBlank(jobids)){
            return HttpResult.error("参数不能为空");
        }
        List<String> jobIdList = Arrays.asList(jobids.split(","));
        String logNr = "";
        Map<String, Object> map = new HashMap<>();
        if (CollectionUtils.isNotEmpty(jobIdList)){
            List<OaJobEntity> jobList = spcySqsxJobService.listByIds(jobIdList);
            if (CollectionUtils.isNotEmpty(jobList)){
                for (OaJobEntity job : jobList) {
                    spcySqsxJobService.removeById(job.getId());
                    OaSpcyJcyFybxdtssxsq nkRsYstpsq = spcyFybxdtssxsqService.getById(job.getFpid());
                    if (nkRsYstpsq != null) {
                        spcyFybxdtssxsqService.removeById(job.getFpid());

                        logNr = "删除出差申请" + job.getFhjmc() + ": ";
                        map = ObjectToMapUtils.objectToMap(nkRsYstpsq);
                        logNr += LogUtils.MapToStringMethod(map);

                        spcyLogService.addLogs(job.getFhjmc(), logNr, job.getFpid(), OaFlowConstant.BXD_TSSXSQ, OaCommonFlowConstant.LOGS_SYS_TYPE_SC);
                    }
                }
            }
        }

        return HttpResult.ok("删除成功");
    }

    /**
     * 编辑
     *
     * @param
     * @return
     */
    @AutoLog(value = " 特殊事项申请-编辑")
    @ApiOperation(value = "特殊事项申请-编辑")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody OaSpcyJcyFybxdtssxsq oaSpcyJcyFybxdtssxsq) {
        spcyFybxdtssxsqService.updateById(oaSpcyJcyFybxdtssxsq);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 判断是否能够删除 特殊事项报销
     */
    @AutoLog(value = "判断是否能够删除 特殊事项报销")
    @ApiOperation(value = "判断是否能够删除 特殊事项报销")
    @GetMapping(value = "/pdsfnsc")
    public HttpResult<?> pdsfnsc(String id) {
        List<OaJobEntity> oaJobEntities = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                .eq(OaJobEntity::getFpid, id)
                .eq(OaJobEntity::getFblzt, OaFlowConstant.FLOW_BLZT_DB));
        if (CollectionUtils.isNotEmpty(oaJobEntities)) {

                if (oaJobEntities.get(0).getFhjmc().equals(OaFlowConstant.TSSXSQ_JBR)){
                    return HttpResult.ok(true);
                }else if (oaJobEntities.get(0).getFhjmc().equals(OaFlowConstant.TSSXSQ_SQ)){
                    return HttpResult.ok(true);
                }else {
                    return HttpResult.ok(false);
                }
        }else {
            return HttpResult.ok(true);
        }

    }

    /**
     * 撤回接口
     */
    @AutoLog(value = "撤回接口")
    @ApiOperation(value = "撤回接口")
    @GetMapping(value = "/chjk")
    public HttpResult<?> chjk(String chztid) {
        OaJobEntity oaJobEntity = spcySqsxJobService.getById(chztid);

        OaJobEntity oaJobEntity1 = spcySqsxJobService.getById(oaJobEntity.getFsyhjid());
        if (oaJobEntity1 != null){
            spcySqsxJobService.removeById(oaJobEntity);
            oaJobEntity1.setFblzt(OaCommonFlowConstant.BLZT_DB);
            spcySqsxJobService.updateById(oaJobEntity1);

            OaSpcyJcyFybxdtssxsq fybxdtssxsq = spcyFybxdtssxsqService.getById(oaJobEntity1.getFpid());
            fybxdtssxsq.setFsffqlc(OaCommonFlowConstant.SFFQLC_NO);
            spcyFybxdtssxsqService.updateById(fybxdtssxsq);
            return HttpResult.ok("撤回成功");
        }
        return HttpResult.ok("撤回失败");


    }








    /**
     * 删除特殊事项报销
     */
    @AutoLog(value = "删除特殊事项报销")
    @ApiOperation(value = "删除特殊事项报销")
    @GetMapping(value = "/sctssx")
    public HttpResult<?> sctssx(String id) {
        List<OaJobEntity> oaJobEntities = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>()
                .eq(OaJobEntity::getFpid, id));
        if (CollectionUtils.isNotEmpty(oaJobEntities)){
            spcySqsxJobService.removeBatchByIds(oaJobEntities);
        }

        spcyFybxdtssxsqService.removeById(id);
        return HttpResult.ok("删除成功");






    }





}
